package cn.lg.soar.system.biz.modules.general.entity;

import cn.lg.soar.common.constant.Format;
import cn.lg.soar.common.util.jackson.annotations.SoarFormat;
import cn.lg.soar.core.annotations.constraints.group.Create;
import cn.lg.soar.core.annotations.constraints.group.Update;
import cn.lg.soar.database.base.entity.BaseEntity;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 数据源
 * @author luguoxiang
 * @since 2022-04-30
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
@Accessors(chain = true)
@Schema(description = "数据源")
@TableName("lg_sys_data_source")
public class DataSource extends BaseEntity {

    @NotBlank(message = "id不能为空", groups = { Create.class, Update.class })
    @ExcelProperty(value = "id")
    @Schema(description = "id")
    @TableId(type = IdType.INPUT)
    private String id;

    @Schema(description = "是否禁用")
    private Boolean disabled;

    @NotBlank(message = "名称不能为空", groups = { Create.class })
    @ExcelProperty(value = "数据源名称")
    @Schema(description = "数据源名称")
    private String name;

    @NotBlank(message = "数据源类名不能为空", groups = { Create.class })
    @ExcelProperty(value = "数据源类名")
    @Schema(description = "数据源类名")
    private String type;

    @NotBlank(message = "路径不能为空", groups = { Create.class })
    @ExcelProperty(value = "数据源路径")
    @Schema(description = "数据源路径")
    private String url;

    @SoarFormat(serialize = Format.USERNAME)
    @NotBlank(message = "用户名不能为空", groups = { Create.class })
    @ExcelProperty(value = "数据源用户名")
    @Schema(description = "数据源用户名")
    private String username;

    @SoarFormat(serialize = Format.PASSWORD)
    @NotBlank(message = "密码不能为空", groups = { Create.class })
    @ExcelProperty(value = "数据源密码")
    @Schema(description = "数据源密码")
    private String password;

    @ExcelProperty(value = "驱动类名")
    @Schema(description = "驱动类名")
    private String driverClassName;

    @Version
    @Schema(description = "乐观锁")
    protected Integer version;

    @JsonIgnore
    @Override
    public Serializable primaryKey() {
        return this.id;
    }

}
